package edu.sctu.xuping.month06.subwaysystem;


import java.util.List;

/**
 * Created by user02 on 2015/6/26.
 */
public class SubwayUtil {
    private String contrabandGoods = "管制刀具,枪,毒品,水";
    private SetPeopleData setpeopledata;
    private SetStationData setstationData;

    public SubwayUtil() {
        this.setstationData = new SetStationData();
        this.setpeopledata = new SetPeopleData();
    }

    public void getPeople() {
        List<PeopleInformation> listpeople = setpeopledata.setPeopleData();
        for (PeopleInformation peopleInformation : listpeople) {
            if (peopleInformation.isIs_Card()) {
                checkPankage(peopleInformation);
            } else {
                System.out.println(peopleInformation.getName() + "请购买地铁卡");

            }
        }
    }

    public String checkPankage(PeopleInformation peopleinformation) {
        PankageHandle pankageHandle = new PankageHandle(peopleinformation, contrabandGoods);
        if (pankageHandle.checkPankage()) {
            System.out.println(peopleinformation.getName() + "携带违禁品，不能进入");
            return null;
        } else {
            return checkWater(peopleinformation);

        }
    }

    public String checkWater(PeopleInformation peopleinformation) {
        PankageHandle pankageHandle = new PankageHandle(peopleinformation, contrabandGoods);
        if (pankageHandle.checkWater()) {
            System.out.println(peopleinformation.getName() + "包裹中含有水,不能进入");
            return null;
        } else {
            return checkPrice(peopleinformation);
        }
    }

    public String checkPrice(PeopleInformation peopleinformation) {
        CardHandle cardHandle = new CardHandle(setstationData.setHashMapDataline1());
        int leftmoney = cardHandle.getPrice(peopleinformation.startstation, peopleinformation.endstation);
        if (peopleinformation.getPice() >= leftmoney) {
            int count1 = peopleinformation.getPice() - leftmoney;
            System.out.println(peopleinformation.getName() + "可以进站，余额为：" + count1);
            return null;
        } else {
            System.out.println(peopleinformation.getName() + "充值成功，可以进站");
            cardHandle.reCharge(10, peopleinformation);
            return null;
        }
    }
}
